package com.atde._03_creational_design_patterns.fcatory.simplefactory.pizzastore.order;


import com.atde._03_creational_design_patterns.fcatory.simplefactory.pizzastore.pizza.CheesePizza;
import com.atde._03_creational_design_patterns.fcatory.simplefactory.pizzastore.pizza.GreekPizza;
import com.atde._03_creational_design_patterns.fcatory.simplefactory.pizzastore.pizza.PepperPizza;
import com.atde._03_creational_design_patterns.fcatory.simplefactory.pizzastore.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @BelongsProject: hsp_java_design_mode
 * @BelongsPackage: com.atde._03_creational_design_patterns.fcatory.simplefactory.pizzastore.order
 * @Author: Del
 * @CreateTime: 2025-06-02  23:09
 * @Description: 订购披萨
 * @Version: 1.0
 */
public class OrderPizza {
//    public OrderPizza() {
//        Pizza pizza = null;
//        // 订购披萨的类型
//        String orderType;
//        do {
//            orderType = createPizza();
//            if (orderType.equals("greek")) {
//                pizza = new GreekPizza();
//                pizza.setName("希腊披萨");
//                pizza.prepare();
//                pizza.bake();
//                pizza.cut();
//                pizza.box();
//                System.out.println("披萨订购完毕");
//            } else if (orderType.equals("cheese")) {
//                pizza = new CheesePizza();
//                pizza.setName("奶酪披萨");
//                pizza.prepare();
//                pizza.bake();
//                pizza.cut();
//                pizza.box();
//                System.out.println("披萨订购完毕");
//            } else if (orderType.equals("pepper")) {
//                pizza = new PepperPizza();
//                pizza.setName("胡椒披萨");
//                pizza.prepare();
//                pizza.bake();
//                pizza.cut();
//                pizza.box();
//                System.out.println("披萨订购完毕");
//            } else {
//                break;
//            }
//        } while (true);
//    }
    // 创建 简单工厂对象
    SimpleFactory simpleFactory;
    // 设置披萨实例为空
    Pizza pizza = null;

    public OrderPizza(SimpleFactory simpleFactory) {
        setSimpleFactory(simpleFactory);
    }

    public void setSimpleFactory(SimpleFactory simpleFactory) {
        // 订购披萨的类型
       String orderType = "";
       // 设置简单工厂对象
       this.simpleFactory = simpleFactory;
       do {
           orderType = createPizza();
           pizza = simpleFactory.CreatePizza(orderType);
           if (pizza != null) {
               pizza.prepare();
               pizza.bake();
               pizza.cut();
               pizza.box();
               System.out.println("披萨订购完毕");
           } else {
               System.out.println("订购披萨失败");
               break;
           }
       } while (true);
    }

   /***
    * @author: Del
    * @date: 2025/6/2 23:15
    * @return String 披萨的类型
    * @description:  用于获取订购披萨的类型
    */
    private String createPizza() {
        try {
            BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
            System.out.print("请输入披萨类型：");
            return buf.readLine();
        } catch (IOException e) {
           e.printStackTrace();
           return "";
        }
    }
}
